home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_7736_000041.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  4.3 KB  |  112 lines

  1. Path: dd.chalmers.se!news.chalmers.se!sunic!ugle.unit.no!trane.uninett.no!eunet.no!EU.net!howland.reston.ans.net!gatech!news-feed-1.peachnet.edu!concert!bigblue.oit.unc.edu!not-for-mail
  2. From: utoddl@guitar.oit.unc.edu (Todd M. Lewis)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: RKRM Libraries mystery: child task and library pointers
  5. Date: 18 Mar 1994 15:32:42 GMT
  6. Organization: The University of North Carolina at Chapel Hill
  7. Lines: 100
  8. Message-ID: <2mchiq$lc6@bigblue.oit.unc.edu>
  9. References: <2m8akk$fua@kruuna.Helsinki.FI>
  10. NNTP-Posting-Host: guitar.oit.unc.edu
  11.  
  12. In article <2m8akk$fua@kruuna.Helsinki.FI> hipoyhon@kruuna.Helsinki.FI (Harri  
  13. I Poyhonen) writes:
  14. >[...]RKRM doesn't
  15. >explicitly state *why* library bases shouldn't be shared, guess it has
  16. >something to do with library data area integrity.
  17.  
  18. superb guessing on your part.  Actually, it could be lots of other
  19. reasons.  If the library isn't documented as being sharable, then
  20. you can only guess, and sooner or later you will guess wrong.
  21.  
  22. >This raises following questions: Can I go on sharing the library pointers? 
  23.  
  24. Yes.
  25.  
  26. >Safely?
  27.  
  28. No.  At least not without some more precautions.
  29.  
  30. >If I make sure that the library is used by at most one task at a time?
  31.  
  32. Not relevant.
  33.  
  34. >What are the library bases that must *not* be shared?
  35.  
  36. Unbounded set.  Only libraries documented as sharable are sharable.
  37. That list is much smaller.  However, consider that BOOPSI methods
  38. get called from Intuition's context.  Therefore anything that gets
  39. done by a BOOPSI method had better be done by dedicated code or by
  40. a sharable library.
  41.  
  42. The rule to follow is that each using task/process _must_ open and
  43. close the libraries it uses.  Now, IF you do that, AND IF the base
  44. value returned by the OpenLibrary() call in each of your tasks
  45. just happens to be the same for a given library, then you can use
  46. the same global variable to hold the library base pointer for all 
  47. your tasks.  If in the future one of these libraries changes on
  48. you and no longer uses the same base for each opener then you
  49. need to handle that gracefully.  The code below handles that.
  50. Use and enjoy
  51.  
  52. /*
  53.  * Call OpenSharableBaseLibrary() to open libraries
  54.  * whose bases must be shared among tasks.  It fails (returns NULL)
  55.  * if the library can't be opened or if the base value returned
  56.  * is not the same as the value the rest of the tasks are using.
  57.  *   The 3rd parameter is a pointer to your global base pointer
  58.  * for the library in question.  DO NOT assign the return value
  59.  * to your global base pointer--the routine does that if it should,
  60.  * and if the library were previously opened and this open failed
  61.  * you would wipe out the global variable that other tasks were
  62.  * using.
  63.  */
  64. struct Library *OpenSharableBaseLibrary( char *libname, 
  65.                                          LONG ver, 
  66.                      struct Library **base )
  67. {
  68.   struct Library *tmpbase;
  69.   
  70.   tmpbase = OpenLibrary( libname, ver );
  71.  
  72.   if ( (*base == NULL)  || ( *base == tmpbase )  )
  73.         *base = tmpbase;
  74.     else
  75.       {
  76.         if ( tmpbase )
  77.       CloseLibrary( tmpbase );
  78.     tmpbase = NULL;
  79.       }
  80.   return tmpbase;
  81. }
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /* Example use in a subtask.  Note that the return value is NOT
  85.  * assigned to the global base pointer.  Note also that
  86.  * every successful open is paired with a close from within the same
  87.  * task.
  88.  *   When closing the library, you cannot assume that a non-NULL global
  89.  * base pointer implies that your task's Open...() was sucessful.  That
  90.  * value may have been supplied by other tasks which may be using the
  91.  * pointer.  You will need some other mechanism to determine whether
  92.  * to close a given library.  (In this example we use the fact that
  93.  * we are in the if()... statement block.)
  94.  */
  95. if ( OpenSharableBaseLibrary( "intuition.library", 0L, &IntuitionBase ) )
  96.   {
  97.     if ( OpenSharableBaseLibrary( "gorp.library", 0L, &GorpBase ) )
  98.       {
  99.         do_neat_task_stuff();
  100.         CloseLibrary( GorpBase );
  101.       }
  102.      else
  103.         task_error( ERROR_LIB_BASE_NOT_SHARABLE, "gorp.library" );
  104.     CloseLibrary( IntuitionBase );
  105.   }
  106.  else
  107.     task_error( ERROR_LIB_BASE_NOT_SHARABLE, "intuition.library" );
  108.  
  109. --
  110. Todd_Lewis@unc.edu   ASDF - Amiga Software Developers Forum
  111.                "Where the Pizza Meets the Code"
  112.